package it.mauriziobasile.dietarapida.database;

import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * 
 * @author Maurizio Basile
 */
public class DBConnect {

    private Connection connection;
    private String[] columns;

    public DBConnect() throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
        Properties prop = new Properties();
        //prop.load(this.getClass().getResourceAsStream("alimentidb.properties"));
        prop.load(new FileReader("alimentidb.properties"));
        Class.forName(prop.getProperty("driver", "org.apache.derby.jdbc.EmbeddedDriver")).newInstance();
        connection = DriverManager.getConnection(prop.getProperty("preurl", "jdbc:derby:") + prop.getProperty("url", "Alimenti") + ";create=false");
        columns = prop.getProperty("tuttecolonne").split(";");
    }

    public Connection getConnection() {
        return connection;
    }
    public String[] getColumns() {
        return columns;
    }
}
